package huiji;

import java.awt.*;

public class HuijiFont extends BaseObj{
    private String value;//文字内容
    private Color color;//字体颜色
    private int size;//字体大小
    private int type = Font.BOLD;//字体类型，默认加粗



    public HuijiFont( String value,Color color, int size) {
        this.color = color;
        this.size = size;
        this.value = value;
        //计算宽高
        setHeight(size);
        setWidth(value.length()*size);
        //计算坐标
        setX(HuijiJPanel.width/2-(this.value.length()*this.size/2));
        System.out.println("X:"+getX());
        setY(HuijiJPanel.height/2-this.size/2);
        System.out.println("Y:"+getY());
    }

    public Color getColor() {
        return color;
    }

    public HuijiFont setColor(Color color) {
        this.color = color;
        return this;
    }

    public int getSize() {
        return size;
    }

    public HuijiFont setSize(int size) {
        this.size = size;
        return this;
    }

    public String getValue() {
        return value;
    }

    public HuijiFont setValue(String value) {
        this.value = value;
        return this;
    }

    public int getType() {
        return type;
    }

    public HuijiFont setType(int type) {
        this.type = type;
        return this;
    }

    @Override
    public void paint(Graphics g) {
        g.setColor(color);//设置颜色
        g.setFont(new Font(Font.SANS_SERIF,type,this.size));//设置字体
        g.drawString(this.value,getX(),getY());
    }
}
